package com.udhtu.ii.lab1;

import static com.udhtu.ii.lab1.Function.*;

/**
 * метод прямого перебора
 */
public class PryamoyPerebor {
    private double epsilon;
    private double left;
    private double right;
    private int count;

    PryamoyPerebor() {
        epsilon = EPSILON;
        left = LEFT;
        right = RIGHT;
    }

    public void compute() {
        double ans, n, h, min, max;
        count=0;
        n = (right - left) / epsilon;
        h = (right - left) / n;
        min = max = function(left);
        for (int i = 1; i <= n; i++) {
            count++;
            left += h;
            ans = function(left);
            if (ans > max)
                max = ans;
            else if (ans < min)
                min = ans;
        }
        System.out.println("Метод прямого перебора:");
        System.out.println("min=" + min + "\nmax=" + max);
        System.out.println("count="+count);
    }


}
